<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">
            <h:form id="userForm" enctype="multipart/form-data">
                 <br/>
                <h3 class="title">Pesquisando Requerimento</h3>
                
                <p:growl id="messages" showDetail="true" autoUpdate="true"  /> 
                <div class="row">
                    <div class="twelve columns"> 
                        <fieldset>
                            <legend> <h4 style="margin:0 0 10px 0">Interessado</h4></legend>
                            <p:panel id="userPanel" style="background: none; border: none;" 
                                    styleClass="container_24 clearfix ">

                                    <p:outputLabel value="Interessado:" styleClass="grid_3"/>
                                    <p:inputText styleClass="grid_20 ajustInput" value="#{managerSearchRequirement.searchReq.interested}" />

                                    <p:outputLabel value="Processo:" styleClass="grid_3"/>
                                    <p:inputText styleClass="grid_8" value="#{managerSearchRequirement.searchReq.process}" />

                                    <p:outputLabel value="Data:" styleClass="grid_3"/>
                                    <p:calendar styleClass="grid_8" showOn="button" value="#{managerSearchRequirement.searchReq.create_at}" />


                            </p:panel>
                        </fieldset>
                        
                        <fieldset>
                            <legend> <h4 style="margin:0 0 10px 0">Proprietário</h4></legend>
                            <p:panel id="intPanel" style="background: none; border: none;" 
                                        styleClass="container_24 clearfix both ">
                                <p:outputLabel value="Pessoa: "  styleClass="grid_3"/>
                                <p:selectOneRadio id="typePerson" style="margin-top:-8px;" styleClass="grid_8"
                                                  value="#{managerSearchRequirement.searchPeople.typeDocument}" >  
                                    <f:selectItems value="#{managerSearchRequirement.typeDocumentList()}" />
                                    <p:ajax event="change" update=":userForm:intPanel" 
                                            />
                                </p:selectOneRadio>

                                <div class="clear"/>

                                <p:outputLabel id="typeDocumentLabel" 
                                                value="#{managerSearchRequirement.searchPeople.typeDocument}: " 
                                                styleClass="grid_3"/>

                                <p:inputMask id="typeDocumentInput" 
                                                value="#{managerSearchRequirement.searchPeople.typeDocument.type eq 'CPF' ? 
                                                        managerSearchRequirement.searchPeople.cpf : managerSearchRequirement.searchPeople.cnpj}"
                                                mask="#{managerSearchRequirement.searchPeople.typeDocument.type eq 'CPF' ? 
                                                        '999.999.999-99':'99.999.999/9999-99'}" 
                                                styleClass="grid_8" > 

                                </p:inputMask>
                                <div class="clear"/>
                                <p:outputLabel value="Nome: " styleClass="grid_3" for="nomeInputText" 
                                                rendered="#{managerSearchRequirement.searchPeople.typeDocument.type eq 'CPF'}"/>
                                <p:inputText id="nomeInputText" styleClass="grid_20 ajustInput" 
                                                value="#{managerSearchRequirement.searchPeople.name}" 
                                                rendered="#{managerSearchRequirement.searchPeople.typeDocument.type eq 'CPF'}" />

                                <p:outputLabel value="Fantasia: " styleClass="grid_3" for="nameFantasyInputText" 
                                                rendered="#{managerSearchRequirement.searchPeople.typeDocument.type eq 'CNPJ'}" />
                                <p:inputText id="nameFantasyInputText" styleClass="grid_20 ajustInput"
                                                value="#{managerSearchRequirement.searchPeople.name_fantasy}" 
                                                rendered="#{managerSearchRequirement.searchPeople.typeDocument.type eq 'CNPJ'}" />
                            </p:panel>
                        </fieldset>

                        <br/>
                        <div class="buttonAction">
                            <p:commandButton value="Pesquisar" icon="ui-icon-search"
                                             update="@form, tableReq, intPanel"
                                             actionListener="#{managerSearchRequirement.searchRequirement()}"
                                             styleClass="ui-priority-primary" />
                            <p:button href="indexrequirement.xhtml" value="Cancelar"  icon="ui-icon-trash" />
                        </div >
                    </div>
                    <fieldset>
                        <legend> <h4 style="margin:0 0 10px 0">Resultado</h4></legend>
                        <p:panel id="resultPanel" style="background: none; border: none;" 
                                 styleClass="container_24 clearfix ">

                            <p:dataTable id="tableReq" var="r" value="#{managerSearchRequirement.searchreqs}" 
                                         styleClass="grid_24"
                                         rowIndexVar="rowid"
                                         rowKey="#{r.id}"
                                         rows="5" paginator="true"  
                                         paginatorPosition="bottom"
                                         emptyMessage="Nenhum registro">  
                                <f:facet name="header">
                                    Requerimento
                                </f:facet>
                                <p:column headerText="Interessado" width="400">  
                                    <h:outputText value="#{r.interested}"/>
                                </p:column>  
                                <p:column headerText="N˚ Processo" width="150">  
                                    <h:outputText value="#{r.process}"/>
                                </p:column>
                                <p:column headerText="Situação">  
                                    <h:outputText value="#{r.status.name}" style="color: red"/>
                                </p:column>

                                <p:column headerText="Ação" width="75">
                                    <p:button  style="width: 20px; height: 20px;" 
                                               title="editar"
                                               href="editreq.xhtml?reqEdit=#{r.id}"
                                               icon="ui-icon-pencil"/>
                                    <p:button  style="width: 20px; height: 20px;" 
                                               title="visualizar"
                                               href="showreq.xhtml?reqShow=#{r.id}"
                                               icon="ui-icon-zoomin"/>

                                </p:column>
                            </p:dataTable> 

                        </p:panel>

                    </fieldset>

                </div>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
